package com.yanqu.road.server.cmd.group;

import com.yanqu.road.entity.rank.cross.CrossUserRank;
import com.yanqu.road.logic.pb.CrossRankPb;
import com.yanqu.road.pb.cross.group.CrossGroupProto;
import com.yanqu.road.pb.rank.RankProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.manager.rank.CrossRankMgr;
import com.yanqu.road.server.manger.ServerGroupMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

import java.math.BigInteger;

@Cmd(code = Protocol.C_CROSS_GROUP_RANK_CHANGE, desc = "跨服分组排行数据变化")
public class CrossGroupRankChangeCmd extends CrossCommand {


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossGroupProto.CrossGroupRankChangeReqMsg reqMsg = CrossGroupProto.CrossGroupRankChangeReqMsg.parseFrom(packet.getBytes());
        int groupId = ServerGroupMgr.getGroupIdByServerId(serverId);
        for (CrossGroupProto.CrossGroupRankChangeMsg msg : reqMsg.getDataList()) {
            RankProto.RankTempMsg temMsg = msg.getData();
            int type = msg.getType();
            int bigType = msg.getBigRankType();
            CrossUserRank crossUserRank = CrossRankPb.parseCrossUserRank(type, temMsg, bigType);
            if (crossUserRank.getValue().compareTo(BigInteger.valueOf(Long.MIN_VALUE)) == 0) {
                crossUserRank.setDelete(true);
            }
            CrossRankMgr.changeUserGroupRank(groupId, bigType, type, crossUserRank);
        }
    }

    @Override
    public void sendData() {

    }
}
